home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / hard / drivr / cyberx10.lha / CyberX10 / Source / wbtocliargs.c < prev    next >
Text File  |  1992-11-06  |  2KB  |  108 lines

  1. STRPTR WBtoCLIargs(struct WBArg * WBArg, STRPTR ArgTemplate)
  2. {
  3.     UBYTE *Argline, *ArglineSave, *SourcePtr, *DestPtr;
  4.     UBYTE tempChar;
  5.     BOOL sawEqual;
  6.     int index;
  7.     ULONG size;
  8.     BPTR oldDir;
  9.     struct DiskObject *dob;
  10.     STRPTR TempBuffer;
  11.  
  12.     if (!(TempBuffer = AllocVec(BIG_BUF_SIZE, MEMF_CLEAR)))
  13.         return NULL;
  14.  
  15.     oldDir = CurrentDir(WBArg->wa_Lock);
  16.  
  17.     if (!(dob = GetDiskObjectNew(WBArg->wa_Name))) {
  18.         CurrentDir(oldDir);
  19.         FreeVec(TempBuffer);
  20.         return NULL;
  21.     }
  22.  
  23.     /*
  24.      * if there are tooltypes then figure out how much memory we need to
  25.      * allocate to hold them as a command line.  anything that isn't a
  26.      * legal argument in our command line template is ignored.  This lets
  27.      * things like DONOTWAIT be used without causing an error at
  28.      * ReadArgs() time.
  29.      */
  30.  
  31.     if (dob->do_ToolTypes)
  32.         for (size = index = 0; dob->do_ToolTypes[index]; index++) {
  33.             SourcePtr = dob->do_ToolTypes[index];
  34.             DestPtr = TempBuffer;
  35.  
  36.             while (tempChar = *SourcePtr++)
  37.                 if (tempChar == '=')
  38.                     break;
  39.                 else
  40.                     *DestPtr++ = tempChar;
  41.  
  42.             *DestPtr = '\0';
  43.  
  44.             if (FindArg(ArgTemplate, TempBuffer) != -1)
  45.                 size += strlen(dob->do_ToolTypes[index]) + 3;
  46.         }
  47.     else
  48.         size = 0;
  49.  
  50.     if (Argline = AllocVec(size + 2, MEMF_CLEAR)) {
  51.         ArglineSave = Argline;
  52.  
  53.         if (dob->do_ToolTypes)
  54.             for (index = 0; dob->do_ToolTypes[index]; index++) {
  55.                 SourcePtr = dob->do_ToolTypes[index];
  56.                 DestPtr = TempBuffer;
  57.                 sawEqual = FALSE;
  58.  
  59.                 while (tempChar = *SourcePtr++)
  60.                     if (tempChar == '=') {
  61.                         sawEqual = TRUE;
  62.                         break;
  63.                     }
  64.                     else
  65.                         *DestPtr++ = tempChar;
  66.  
  67.                 *DestPtr = '\0';
  68.  
  69.                 if (FindArg(ArgTemplate, TempBuffer) != -1) {
  70.                     CopyMem(TempBuffer, Argline, DestPtr - TempBuffer);
  71.                     Argline += DestPtr - TempBuffer;
  72.  
  73.                     /*
  74.                      * if we saw an equals sign when we
  75.                      * broke the argument name out then
  76.                      * we know we need to copy the
  77.                      * argument's data over.  if we
  78.                      * didn't see it then this argument
  79.                      * is a switch and thus has no more
  80.                      * data to copy over
  81.                      */
  82.  
  83.                     if (sawEqual) {
  84.                         *Argline++ = ' ';
  85.                         *Argline++ = '\"';
  86.  
  87.                         while (tempChar = *SourcePtr++)
  88.                             *Argline++ = tempChar;
  89.  
  90.                         *Argline++ = '\"';
  91.                     }
  92.  
  93.                     *Argline++ = ' ';
  94.                 }
  95.             }
  96.  
  97.         *Argline++ = '\n';
  98.         *Argline = '\0';
  99.     }
  100.     else
  101.         ArglineSave = NULL;
  102.  
  103.     FreeDiskObject(dob);
  104.     CurrentDir(oldDir);
  105.     FreeVec(TempBuffer);
  106.     return ArglineSave;
  107. }
  108.